﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RndLRMovCtrl : MonoBehaviour {

    public float marginLR;
    public float movSpeed;

    private float LRFlag;

    void Awake()
    {
        LRFlag = Mathf.Sign(Random.Range(-1f, 1f));
    }

	void FixedUpdate () {
        if (LRFlag < 0)
        {
            //左移动
            if (transform.position.x > -marginLR)
            {
                transform.position = new Vector2(transform.position.x - movSpeed, transform.position.y);
            }
            else
            {
                LRFlag = 1;
            }
        }
        else
        {
            //右移动
            if (transform.position.x < marginLR)
            {
                transform.position = new Vector2(transform.position.x + movSpeed, transform.position.y);
            }
            else
            {
                LRFlag = -1;
            }
        }
	}
}
